package com.aiti.lulian.service;

import com.aiti.base.core.base.dto.PageDto;
import com.aiti.base.core.page.PageInfo;
import com.aiti.base.core.page.PageResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.List;
import java.util.function.Supplier;

public interface PageService {

    /**
     * 分页查询，用法示例：
     * IPage<StarEnterpriseInfoVo> page = new Page<>(queryDto.getPageNum(), queryDto.getPageSize());
     * PageResult<StarEnterpriseInfoVo> pageResult = this.executePageQuery(queryDto, page, () -> this.baseMapper.queryIndustryStarEnterpriseList(page, queryDto));
     */
    default <T extends PageDto, R> PageResult<R> executePageQuery(T pageDto, IPage<R> page, Supplier<List<R>> queryFunction) {
        List<R> list = queryFunction.get();
        return new PageResult<>(list, new PageInfo(pageDto.getPageNum(), pageDto.getPageSize()), page.getTotal());
    }
}
